<template>
  <div>
    <!-- data表格的数据 -->
    <!--default-expand-all 默认展开所有子菜单 -->
   <div class="bigBox">
      <el-table class="smBox"
      :data="tableData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
    >
      <!-- prop:数据的字段名 -->
      <!-- label:标签名 -->
      <!-- sortable:是否可以排序 -->
<<<<<<< HEAD
      <el-table-column prop="id" label="ID"> </el-table-column>
      <el-table-column prop="rolename" label="角色名称"> </el-table-column>
=======
<<<<<<< HEAD
      <el-table-column prop="id" label="ID"> </el-table-column>
      <el-table-column prop="rolename" label="角色名称"> </el-table-column>
=======
      <el-table-column prop="id" label="ID" width="130"> </el-table-column>
      <el-table-column prop="rolename" label="角色名称" width="130"> </el-table-column>
>>>>>>> d519b3a9147c56fc3b4298a9549da21438cdf484
>>>>>>> bab7c7a15a7723f417b1c3b2179ae51ae1f154c9
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 1" type="success">正常</el-tag>
          <el-tag v-else type="danger">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            circle
            @click="edit(scope.row)"
          ></el-button>
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            circle
            @click="del(scope.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
   </div>
  </div>
</template>

<script>
import {roleDel} from '../../request'
export default {
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    this.getRoleList();
    // 通过bus的$on的方法开启监听
    this.$bus.$on('update',()=>{
      this.getRoleList()
    })
  },

  methods: {
    // 获取角色列表
    getRoleList() {
      this.$http("/rolelist")
        .then((res) => {
          //   console.log(res);
          // 根据接口数据，赋值
          this.tableData = res.list;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 编辑角色
    edit(info) {
      console.log(info);
<<<<<<< HEAD
      this.$emit("edit",{...info})
=======
<<<<<<< HEAD
      this.$emit("edit",{...info})
=======
>>>>>>> d519b3a9147c56fc3b4298a9549da21438cdf484
>>>>>>> bab7c7a15a7723f417b1c3b2179ae51ae1f154c9
    },
    // 删除菜单弹窗
    del(id) {
      // 弹窗，二次确认
      this.$confirm("确定删除吗, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        // 点击确认按钮
        .then(() => {
          // 真的要删了
          this.delRole(id);

        })
        // 点击取消按钮
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
   
    },
   async delRole(id){
      let res = await roleDel(id)
         this.tableData = res.list;
    }
  },
};
</script>

<style>
  .bigBox{
    overflow: hidden;
    margin-top: 18px;
    width: auto;
    height: auto;
    background-color: #FFF;
  }
  .bigBox .smBox{
    margin: 8px 18px 19px 18px;
  }
</style>